<template>
  <div class="ipt">
    <textarea v-model="val"></textarea>
    <button @click="sendComment">提交评论</button>
  </div>
</template>
<script>
import * as commentApi from "@/api";
import { mapActions } from "vuex";
export default {
  data() {
    return {
      val: "",
    };
  },
  methods: {
    ...mapActions(["GET_COMMENT_LIST"]),
    sendComment() {
      let name = prompt("请输入你的昵称:");
      //必须输入昵称,也输入了内容
      if (name && this.val) {
        //发送请求，提交评论
        commentApi.addComments(this.val, name).then((res) => {
          // console.log(res);
          if (res.data.state) {
            //更新视图
            //重新调用action 发送请求 更新数据
            this.GET_COMMENT_LIST();
            this.val = "";
          }
        });
      }
    },
  },
};
</script>
<style scoped>
textarea {
  width: 100%;
  min-height: 100px;
  resize: none;
  font-size: 20px;
}
button {
  border: none;
  border-radius: 4px;
  padding: 6px 18px;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  color: #fff;
  background: deepskyblue;
  cursor: pointer;
  outline: none;
}
button:hover {
  background: #0e95c2;
}
</style>
